package com.hustcad.es.controller;

import com.hustcad.es.msg.Result;
import com.hustcad.es.service.EsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.index.Index;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by wangwen on 2019/9/23 9:34
 */
@Controller
@ApiOperation("全文检索操作接口")
public class EsController {

    @Autowired
    private EsService esService;

    @ApiOperation("检索文档")
    @RequestMapping(value = "/searchDoc",method = RequestMethod.GET)
    @ResponseBody
    public Result searchDocument(String index, String keyword) {
        return esService.searchDocument(index,keyword);
    }


    @ApiOperation("文档写入(修改)")
    @RequestMapping(value = "/insertDoc",method = RequestMethod.POST)
    @ResponseBody
    public Result uploadFile(String indexName,String oid, String name) {
        return esService.uploadFile(indexName,oid,name);
    }


    @ApiOperation("文档删除")
    @RequestMapping(value = "/deleteDoc",method = RequestMethod.DELETE)
    @ResponseBody
    public Result deleteDocument(String indexName,String oid){
       return esService.deleteDocument(indexName,oid);
    }


    @ApiOperation("添加索引")
    @RequestMapping(value = "/addIndex",method = RequestMethod.POST)
    @ResponseBody
    public Result addIndex(String indexName){
        return esService.addIndex(indexName);
    }

}
